<?php
	include('functions.php');
	date_default_timezone_set('Europe/Copenhagen');	
	if(isset($_GET['create'])) {
//		$cursor = q('posts')->ensureIndex(array('rating' => -1, 'tags' => 1, 'date' => 1));
//		$cursor = q('posts')->ensureIndex(array('rating' => -1, 'tags' => 1));
		$cursor = q('posts')->ensureIndex(array('post' => 1));
		redirect_to('explain.php?msg=1');
	} elseif(isset($_GET['remove'])) {
		set_time_limit(0);
		ini_set("memory_limit","500M");
		$cursor = q('posts')->deleteIndexes();
		redirect_to('explain.php?msg=2');
	}
	
	if(isset($_GET['msg'])) {
			if($_GET['msg'] == 1) {
				echo "<h1>Index created</h1>";
			} else {
				echo "<h1>Index removed</h1>";
			}
	}
	
	// 2.1:
	echo "Case Sensitve<br />";
	$query1 = array('post' => new MongoRegEx('/lorem ipsum/'));
	$cursor = q('post')->find($query1)->explain();
	var_dump($cursor);
		
	// 2.2:
	echo "Case Insensitve<br />";
	$query2 = array('post' => new MongoRegEx('/lorem ipsum/i'));
	$cursor = q('post')->find($query2)->explain();
	var_dump($cursor);
	
//	var_dump($cursor);
//	var_dump($cursor['indexBounds']['rating']);
//	echo $cursor->count();
	
	










?>